/**
 *  @file BufferedReadStream.h
 */
#ifndef _BUFFEREDREADSTREAM_H_
#define _BUFFEREDREADSTREAM_H_

#include "Stream.h"


namespace cppflib
{

// forward declaration
namespace collections { class CircularBuffer; }

namespace io
{

/**
 *  A stream which can buffer the data read from another stream
 */
class _DLLAPI BufferedReadStream : public ReadStream
{
private:
    ptr_t readPos;  ///< readPos is a value between 0 and pCirBuf->GetValidLength() (inclusive)
    Stream *pOrgStream;
    collections::CircularBuffer *pCirBuf;

private:
    BufferedReadStream(void);

public:    
    BufferedReadStream(Stream *pStream, sz_t bufferSize);
    explicit BufferedReadStream(Stream *pStream);
    virtual ~BufferedReadStream(void);

    virtual void Close();
    virtual sz_t CanReadNoBlocking();
    virtual int Read(collections::ArrayByte &buffer);
    virtual int Read(collections::ArrayByte &buffer, int offset, int count);
    virtual int Read();   
    virtual i64_t Seek(i64_t offset, seekorigin_t origin);
};

} // end of namespace io

} // end of namespace cppflib

#endif
